import * as path from 'path'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import { UserConfigExport, defineConfig } from 'vite'
import removeConsole from 'vite-plugin-remove-console'
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
export default defineConfig(({ command }) => {
  const config: UserConfigExport = {
    build: {
      assetsDir: 'assets',
      outDir: '../www/admin',
      // 消除打包大小超过500kb警告
      chunkSizeWarningLimit: 4000,
    },
    resolve: {
      alias: { '@': path.resolve(__dirname, 'src') },
    },
    plugins: [
      vue(),
      removeConsole(),
      AutoImport({
        dts: false,
        imports: ['vue'],
      }),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false, // css in js
          }),
        ],
      }),
    ],
    server: { port: 1230, open: false, host: '0.0.0.0' },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            /** less 全局变量 */
          },
          javascriptEnabled: true
        }
      }
    },
  }

  /** 生产环境执行 */
  if (command == 'build') {
    config.base = '/admin'
  }

  return config
})
